<?php

namespace App\Http\Controllers;

use AipNlp;
use App\Library\Logic\AuctionLogic;
use App\Library\Logic\AuctionOrderLogic;
use App\Library\Service\WxMessageService;
use App\Models\AuctionBidModel;
use App\Models\OpenIdModel;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Hash;

class DemoController extends BaseController
{
    public function index(): JsonResponse
    {
        /*// 加密密码
        $password = Hash::make('Zs666888');
        echo $password;die;*/
      /*  $info = AuctionOrderLogic::query()->where('id',1)->first();
        return success(json_decode($info->receive_info,true)['ua_address_full']);*/
        $list = AuctionOrderLogic::query()->where([
            'status_delete' => 0,
            'status_cancel' => 0,
            'status_pay' => 1,
            'is_push' => 0,
        ])->where([
            ['pay_at', '>', now()->subSeconds(5)->format('Y-m-d H:i:s')],
        ])->get();

        //if (is_null($list)) return;
        foreach ($list as $val) {
            $bidUserIdArr = AuctionBidModel::query()->where('auction_id', $val['id'])
                ->pluck('user_id')->toArray();
            if (!empty($bidUserIdArr)) {
                $openList = OpenIdModel::query()
                    ->distinct()->whereIn('user_id', array_unique($bidUserIdArr))->get();
                if (!empty($openList)) {
                    foreach ($openList as $oVal) {
                        WxMessageService::auctionWxMess($val, $oVal);
                    }
                }
            }
            $sellerOpen = OpenIdModel::query()
                ->where('user_id', $val['seller_id'])->first();
            if (!empty($sellerOpen)) {
                WxMessageService::auctionWxMess($val, $sellerOpen,2);
            }
            $val->is_push = 1;
            $val->save();
        }
        return success();
    }

    public function read()
    {
        $client = new AipNlp(
            '116157994',
            'yP1QdPZTt330hK0TzaCnnFcu',
            '41FXVEed8lRVr8REOuAtoMX6OrwuEzPx'
        );
        $client->address(request()->post('content'));
        dd($client->address(request()->post('content')));
        return request()->post();
    }
}
